package com.dreamcar.inventory.util;

import java.io.UnsupportedEncodingException;
import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

import com.dreamcar.auction.entity.PurchaseOrder;

public class MailSenderUtil {
	
	public static void sendIssuePOMail(PurchaseOrder purchaseOrder, String name, String toAddress){
		Properties props = new Properties();
        Session session = Session.getDefaultInstance(props, null);

        String msgBody = "Este es el mensaje del correo";

        try {
            Message msg = new MimeMessage(session);
            try {
				msg.setFrom(new InternetAddress("mendoza.cuauhtemoc@gmail.com", "Cuauhtemoc Isaac"));
				msg.addRecipient(Message.RecipientType.TO,
						new InternetAddress("mendoza.cuauhtemoc@gmail.com", "Mr. Cuauhtemoc"));
			} catch (UnsupportedEncodingException e) {
				throw new RuntimeException("Imposible enviar correo");
			}
            msg.setSubject("Este es el asunto del correo");
            msg.setText(msgBody);
            Transport.send(msg);

        } catch (AddressException e) {
           e.printStackTrace();
        } catch (MessagingException e) {
            e.printStackTrace();
        }
	}

}
